﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL.DateSet;
using BLL.Wrapper;
using System.Collections.Generic;
using System.Data.SqlClient;

public partial class ProductLocationManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            return;
        }
        init();
    }

    protected void TypeSelecetChanged(object sender, EventArgs e)
    {
        string name = Typelist.SelectedValue;
        TypeWrapper wrapper = new TypeWrapper();
        List<string> list = new List<string>();
        list = wrapper.getSubName(name);
        list.Add("添加");
        TypeClass.DataSource = list;
        TypeClass.DataBind();
        string classname = TypeClass.SelectedValue;
        if (name.Equals("添加") || classname.Equals("添加"))
        {
            ButtonQuery.Visible = true;
            GoodsName.Visible = true;
            GoodsNameInput.Visible = true;
            GoodsNameInput.Text = "";
            if (name.Equals("添加"))
            {
                GoodsName.Text = "省份名";
            }
        }
        else
        {
            ButtonQuery.Visible = false;
            GoodsName.Visible = false;
            GoodsNameInput.Visible = false;
 
        }
    }

    protected void ClassSelecetChanged(object sender, EventArgs e)
    {
        string name = Typelist.SelectedValue;
        string classname = TypeClass.SelectedValue;
        if (name.Equals("添加") || classname.Equals("添加"))
        {
            ButtonQuery.Visible = true;
            GoodsName.Visible = true;
            GoodsNameInput.Visible = true;
            GoodsNameInput.Text = "";
            if (name.Equals("添加"))
            {
                GoodsName.Text = "省份名";
            }
        }
        else
        {
            ButtonQuery.Visible = false;
            GoodsName.Visible = false;
            GoodsNameInput.Visible = false;

        }
    }

    protected void QueryClick(object sender, EventArgs e)
    {
        TypeWrapper wrapper = new TypeWrapper();
        DAL.DateSet.Type.TypeDataTable table = new DAL.DateSet.Type.TypeDataTable();
        DAL.DateSet.Type.TypeRow row;
        row = table.NewTypeRow();
        if (Typelist.SelectedValue.Equals("添加"))
        {
            row.typeName = GoodsNameInput.Text;
            row.typeLevel = wrapper.getLevelByName(Typelist.SelectedValue) + 1; 
            row.parentID = wrapper.getIDByName("中国");
            row.typeFlag = 1;
            row.typeCreateDate = DateTime.Now;
            row.typeCreator = "someone";
            row.englishName = "";
        }
        else
        {
            row.typeName = GoodsNameInput.Text;
            row.parentID = wrapper.getIDByName(Typelist.SelectedValue);
            row.typeFlag = 1;
            row.typeLevel = wrapper.getLevelByName(Typelist.SelectedValue) + 1;
            row.typeCreateDate = DateTime.Now;
            row.typeCreator = "someone";
            row.englishName = "";
            
        }
        wrapper.addARecord(row);
        GoodsName.Text = "城市名";
        init();
    }

    public void init()
    {
        TypeWrapper wrapper = new TypeWrapper();
        List<string> list = new List<string>();
        list = wrapper.getSubName("中国");
        Typelist.DataSource = list;
        list.Add("添加");
        Typelist.DataBind();
        list.Clear();
        list = wrapper.getSubName(Typelist.SelectedValue);
        list.Add("添加");
        TypeClass.DataSource = list;
        TypeClass.DataBind();
        string name = Typelist.SelectedValue;
        string classname = TypeClass.SelectedValue;
        if (name.Equals("添加") || classname.Equals("添加"))
        {
            ButtonQuery.Visible = true;
            GoodsName.Visible = true;
            GoodsNameInput.Visible = true;
            GoodsNameInput.Text = "";
            if (name.Equals("添加"))
            {
                GoodsName.Text = "省份名";
            }
        }
        else
        {
            ButtonQuery.Visible = false;
            GoodsName.Visible = false;
            GoodsNameInput.Visible = false;

        }
    }
}
